package com.kuangstudy.thread.demo2;

/**
 * @author Losca
 * @date 2021/7/19 14:33
 * 静态代理模式
 * 真实对象和代理对象都要实现同一个接口
 * 好处
 * 代理对象可以做真实对象做不了的事情
 * 真实对象专注做自己的事
 *
 * 多线程底层就是用代理
 */
public class Demo2 {
    public static void main(String[] args) {
        MarryCompany marryCompany = new MarryCompany(new You());
        marryCompany.happy();
        You you = new You();
        new Thread(()-> System.out.println("我爱你")).start();
    }

}
interface Marry{
    void happy();
}

class You implements Marry{

    @Override
    public void happy() {
        System.out.println("秦老师结婚了，超开心");
    }
}

class MarryCompany implements Marry{

    private Marry target;

    public MarryCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void happy() {
        before();
        this.target.happy();//真实对象
        after();

    }

    private void after() {
        System.out.println("结婚之后收礼金");
    }

    private void before() {
        System.out.println("结婚前布置结婚现场");
    }
}
